package ru.ntcreb.csir.libs.methods.SVCH.xml.handler;

import java.util.Map;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class SVCHImpulseParserHandler extends DefaultHandler {

	private Map<Double, Double> result;

	public SVCHImpulseParserHandler(Map<Double, Double> result) {
		this.result = result;
	}

	private boolean inputTimeFlag = false;
	private boolean outputVoltageBool = false;

	private double tempInputTime;
	private double tempOutputVoltage;

	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {

		if (qName.equalsIgnoreCase("inputTime")) {
			inputTimeFlag = true;
		}

		if (qName.equalsIgnoreCase("outputVoltage")) {
			outputVoltageBool = true;
		}
	}

	public void endElement(String uri, String localName, String qName)
			throws SAXException {

		if (qName.equalsIgnoreCase("entry")) {
			result.put(tempInputTime, tempOutputVoltage);
		}

	}

	public void characters(char ch[], int start, int length)
			throws SAXException {

		if (inputTimeFlag) {
			tempInputTime = new Double(new String(ch, start, length));
			inputTimeFlag = false;

		}

		if (outputVoltageBool) {

			tempOutputVoltage = new Double(new String(ch, start, length));
			outputVoltageBool = false;
		}

	}

}
